<template>
  <div class="header-container">
    <span class="title">当前科目：{{ `${route.query.kmdm}（${route.query.kmmc}）` }}</span>
    <span class="title">当前题型：</span>
    <span class="title !text-[#F10808]" >{{ questionsInfo.tmlx }}</span>
    <span class="title !text-[#F10808]">({{ questionsInfo.tmbh }})</span>
    <span class="title !text-[#F10808]">{{ statusEnum[route.query?.pyjd] }}</span>
    <span class="time">
      阅卷时长： {{ dayjs.duration(Data.timeNum || 0).format('HH:mm:ss') }}
    </span>
    <span class="flex"></span>
    <slot></slot>
    <span class="label exit" @click="dropOut"> 退出阅卷 </span>
  </div>
</template>

<script setup lang="ts">
import { useRoute, useRouter } from 'vue-router'
const route:any = useRoute()
const router = useRouter()

import { computed, h, reactive, watchEffect, onMounted, onUnmounted } from 'vue'

import dayjs from 'dayjs'
import duration from 'dayjs/plugin/duration'
dayjs.extend(duration)

import { useMessage } from '/@/hooks/web/useMessage'
const { createConfirm, createMessage } = useMessage()

import { statusEnum } from '/@/enums/privateEnums'

import { getAuthCache } from '/@/utils/auth'

import { useTeacherMarkStore } from '/@/store/modules/teacherMark'
const teacherMarkStore = useTeacherMarkStore()
const questionsInfo = computed(() => teacherMarkStore.getQuestions)



const Data: any = reactive({
  timeNum: 0,
  timer: null,
  nowTime: 0,
})

// 计算评阅时长
watchEffect(() => {
  Data.timeNum = Number(Data.nowTime - getAuthCache('pointOfTime'))
})

// 退出阅卷
const dropOut = () => {
  createConfirm({
    iconType: 'warning',
    title: () => h('span', '温馨提醒'),
    content: () => h('span', '您确定退出阅卷页面吗？'),
    onOk: async () => {
      router.back()
    },
  })
}

onMounted(() => {
  clearInterval(Data.timer)
  Data.timer = setInterval(() => {
    Data.nowTime = new Date().getTime()
  }, 1000)
})

onUnmounted(() => {
  clearInterval(Data.timer)
})
</script>

<style lang="less" scoped>
.header-container {
  width: 100%;
  height: 50px;
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 0 20px 5px 20px;

  .title {
    font-size: 18px;
    font-weight: bold;
    color: #3f4355;
    margin-right: 20px;
  }

  .time {
    margin-left: 30px;
    font-size: 100%;
    color: #3f4355;
  }

  .countdStyle {
    margin-left: 30px;
    font-size: 18px;
    font-weight: 700;
    display: flex;
    align-items: center;
    color: orange;
  }

  .label {
    cursor: pointer;
    margin-right: 16px;
    margin-left: 5px;
    font-weight: 700;
  }

  .show {
    color: #00baad;
  }

  .restore {
    color: #3e98e8;
  }

  .error {
    color: rgb(240, 10, 10);
  }

  .exit {
    width: 100px;
    height: 36px;
    background: #136cc4;
    border-radius: 4px;
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-left: 40px;
    cursor: pointer;
  }

  .line {
    height: 100%;
    width: 1px;
    background: #dddada;
  }
}
</style>
